/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.esdc.librarysystem.entity;

import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.util.*;
import javax.persistence.CascadeType;
import javax.persistence.Temporal;
import javax.persistence.OneToMany;
import javax.persistence.ManyToOne;


@Entity
public class BookEntity implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private int copyNumber;
    @Temporal(value = javax.persistence.TemporalType.DATE)
    private Date loanDate;
    @Temporal(value = javax.persistence.TemporalType.DATE)
    private Date dueDate;

    @OneToMany(cascade = {CascadeType.ALL}, mappedBy = "book")
    private Set<ReservationEntity> reservations;
    @ManyToOne
    private TitleEntity title;
    @ManyToOne
    private MemberEntity member;

    public void BookEntity () {
    }

    public void create (int copyNumber, Date dueDate, Date loanDate, TitleEntity title) {
        this.setCopyNumber(copyNumber);
        this.setDueDate(dueDate);
        this.setLoanDate(loanDate);
        this.setTitle(title);
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public int getCopyNumber() {
        return copyNumber;
    }

    public void setCopyNumber(int copyNumber) {
        this.copyNumber = copyNumber;
    }

    public Date getLoanDate() {
        return loanDate;
    }

    public void setLoanDate(Date loanDate) {
        this.loanDate = loanDate;
    }

    public Date getDueDate() {
        return dueDate;
    }

    public void setDueDate(Date dueDate) {
        this.dueDate = dueDate;
    }

    public Set<ReservationEntity> getReservations() {
        return reservations;
    }

    public void setReservations(Set<ReservationEntity> reservations) {
        this.reservations = reservations;
    }

    public TitleEntity getTitle() {
        return title;
    }

    public void setTitle(TitleEntity title) {
        this.title = title;
    }

    public MemberEntity getMember() {
        return member;
    }

    public void setMember(MemberEntity member) {
        this.member = member;
    }


    @Override
    public int hashCode() {
        int hash = 0;
        hash += (getId() != null ? getId().hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof BookEntity)) {
            return false;
        }
        BookEntity other = (BookEntity) object;
        if ((this.getId() == null && other.getId() != null) || (this.getId() != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "ejb.BookEntity[id=" + getId() + "]";
    }

}
